# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl NAP.t'

use Test::More tests => 29;
BEGIN { use_ok('Bio::Phylo::BioPrio') };
BEGIN { use_ok('Bio::Phylo::BioPrio::SetSolution') };

#########################
#Test the SetSolution mechanism

my $sol;
$sol = Bio::Phylo::BioPrio::SetSolution->new;

ok( defined($sol) && ref $sol eq 'Bio::Phylo::BioPrio::SetSolution', 'SetSolution new' );

#Create a fairly random solution that does not obey normal greedy properties
ok($sol->add_transition([],['a'],[1],[1]),'SetSolution->add_transition' );
ok($sol->add_transition([],['b'],[1],[1]),'SetSolution->add_transition' );
ok($sol->add_transition(['c'],['b'],[1],[1])==0,'Bad SetSolution->add_transition' );
ok($sol->add_transition(['a'],['c'],[2],[1]),'SetSolution->add_transition' );
ok($sol->add_transition(['b'],['d'],[1],[.5]),'SetSolution->add_transition' );
ok($sol->add_transition(['a','c'],['b'],[1],[1]),'SetSolution->add_transition' );
ok($sol->add_transition(['b','d'],['f'],[1],[.2]),'SetSolution->add_transition' );
ok($sol->add_transition(['b','d','f'],['g'],[3],[0.01]),'SetSolution->add_transition' );
ok($sol->add_transition(['b','d','f','g'],['h'],[1],[.1]),'SetSolution->add_transition' );
ok($sol->add_transition(['b','d','f','g'],['k'],[1],[.1]),'SetSolution->add_transition' );
ok($sol->add_transition(['b','d','f','g'],['l'],[1],[.1]),'SetSolution->add_transition' );

is($sol->get_solution_cost('b','d','f','g','h'),1.81,'SetSolution->get_solution_cost' );
is($sol->get_solution_epd('b','d','f','g'),6,'SetSolution->get_solution_epd' );

my @all_sol = $sol->get_solutions_all;
is(scalar @all_sol,11,'SetSolution->get_solutions_all');

my @n_sol = $sol->get_solutions_n(4);
is(scalar @n_sol,1,'SetSolution->get_solutions_n');

@n_sol = $sol->get_solutions_n(5);
is(scalar @n_sol,3,'SetSolution->get_solutions_n');

my @cost_sol = $sol->get_solutions_cost(2);
is (scalar @cost_sol, 1, 'SetSolution->get_solutions_cost');

@cost_sol = $sol->get_solutions_cost(1.7);
is (scalar @cost_sol, 2, 'SetSolution->get_solutions_cost');

@cost_sol = $sol->get_solutions_cost(1.75);
is (scalar @cost_sol, 4, 'SetSolution->get_solutions_cost');

is ($sol->get_pd_for_budget(.5),.5,'SetSolution->get_pd_for_budget');
is ($sol->get_pd_for_budget(1.25),1.5,'SetSolution->get_pd_for_budget');

my %b_pd_points = $sol->get_budget_pd_points;

is_deeply (\%b_pd_points,{0=>0,1=>1,1.5=>2,2=>3,3=>4,1.7=>3,1.71=>6,1.81=>7},'SetSolution->get_budget_pd_points');

my %min = $sol->get_min;
my %max = $sol->get_max;
my %mean = $sol->get_mean;
is ($min{c},2,'SetSolution->get_min');
is ($min{b},1,'SetSolution->get_min');
is ($max{b},3,'SetSolution->get_max');
is ($mean{b},2,'SetSolution->get_mean');

#########################
#Test the SetSolution mechanism
